package com.tianhui.consignortwofei.other.auth.recognition.recognitionResultProcess;

import android.text.TextUtils;

import com.fgs.common.utils.DateUtil;
import com.fgs.common.utils.LogUtil;
import com.tianhui.consignortwofei.mvp.model.enty.authLicense.DriverLicenseInfo;
import com.tianhui.consignortwofei.mvp.model.enty.ocrResult.driverLicense.DriverLicenseResult;
import com.xuexiang.xutil.net.JsonUtil;

/**
 * @author fgs
 * @date 2020/11/16
 * @description
 **/
public class DriverLicenseOcrResultProcess {

    public DriverLicenseInfo getDriverOcrResult(DriverLicenseResult result) {
        DriverLicenseInfo driverLicenseInfo = new DriverLicenseInfo();

        if (result == null) {
            return driverLicenseInfo;
        }
        if (result.getStartDate() != null) {
            String string = result.getStartDate().getWords();
            if (!TextUtils.isEmpty(string)) {
                driverLicenseInfo.validperiodfrom = dateFormat(string);
            }
            LogUtil.print("获取驾驶证生效日期", driverLicenseInfo.validperiodfrom);
        }
        if (result.getEndDate() != null) {
            String string = result.getEndDate().getWords();
            driverLicenseInfo.driverlicenseendtime = dateFormat(string);
            LogUtil.print("获取驾驶证失效日期", driverLicenseInfo.driverlicenseendtime);
        }
        //驾驶证类型
        if (result.getVehicleType() != null) {
            String type = result.getVehicleType().getWords();
            driverLicenseInfo.transporttypename = type;
            LogUtil.print("驾驶证类型", type);
        }
        //驾驶证号
        if (result.getNumber() != null) {
            String number = result.getNumber().getWords();
            driverLicenseInfo.qualificationnumber = number;
            LogUtil.print("驾驶证号", number);
        }
        //姓名
        if (result.getName() != null) {
            String name = result.getName().getWords();
            driverLicenseInfo.name = name;
            LogUtil.print("姓名", name);
        }
        //地址
        if (result.getAddress() != null) {
            String address = result.getAddress().getWords();
            driverLicenseInfo.address = address;
            LogUtil.print("住址", address);
        }
        LogUtil.print("driverLicenseInfo", JsonUtil.toJson(driverLicenseInfo));
        return driverLicenseInfo;
    }

    public String dateFormat(String date) {
        return DateUtil.validDateFormat(date, "yyyyMMdd");
    }
}
